﻿using Cache;
using DtoFw;
using DtoFw.Base;
using DtoFw.Common.Query;
using DtoFw.Query;
using Microsoft.AspNetCore.Mvc;
using Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SceneEvidenceAPI.Controllers
{
    /// <summary>
    /// 仓库
    /// </summary>
    [Route("api/room")]
    public class RoomController : BaseController
    {
        private readonly RoomService _roomService;
        public RoomController(RoomService roomService)
        {
            this._roomService = roomService;
        }
        /// <summary>
        /// 添加区域
        /// </summary>
        /// <returns></returns>
        [HttpPost("area/post")]
        public BaseResult PostArea([FromBody] AreaPostDto dto)
        {
            return _roomService.PostArea(dto);
        }
        /// <summary>
        /// 编辑区域
        /// </summary>
        /// <returns></returns>
        [HttpPut("area/put")]
        public BaseResult PutArea([FromBody] AreaPutDto dto)
        {
            return _roomService.PutArea(dto);
        }

        /// <summary>
        /// 获取用户对象
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("area/get/{id}")]
        public BaseGenericResult<AreaQueryDto> GetAreasInfo(long id)
        {
            return _roomService.QueryAreasById(id);
        }

        /// <summary>
        /// 查询区域
        /// </summary>
        /// <returns></returns>
        [HttpPost("area/query")]
        public BaseGenericResult<List<AreaQueryDto>> QueryAreas(CommonQuery query)
        {
            return _roomService.QueryAreas(query);
        }
        /// <summary>
        /// 删除区域
        /// </summary>
        /// <returns></returns>
        [HttpDelete("area/delete")]
        public BaseResult DeleteArea([FromBody] DeleteSingleDto query)
        {
            return _roomService.DeleteArea(query);
        }
        /// <summary>
        /// 添加柜子
        /// </summary>
        /// <returns></returns>
        [HttpPost("cabinet/post")]
        public BaseResult PostCabinet([FromBody] CabinetPostDto dto)
        {
            return _roomService.PostCabinet(dto);
        }

        /// <summary>
        /// 添加柜子
        /// </summary>
        /// <returns></returns>
        [HttpPost("cabinet/addcol")]
        public BaseResult AddMCabinetsCol([FromBody] CabinetPostDto dto)
        {
            return _roomService.AddMCabinetsCol(dto);
        }

        /// <summary>
        /// 编辑柜子
        /// </summary>
        /// <returns></returns>
        [HttpPut("cabinet/put")]
        public BaseResult PutCabinet([FromBody] CabinetPutDto dto)
        {
            return _roomService.PutCabinet(dto);
        }

        /// <summary>
        /// 复制柜子
        /// </summary>
        /// <returns></returns>
        [HttpGet("cabinet/{id}/copy")]
        public BaseResult CopyCabinet(long id)
        {
            return _roomService.CopyCabinet(id);
        }

        /// <summary>列
        /// 密集柜复制
        /// </summary>
        /// <returns></returns>
        [HttpGet("cabinet/{cabinetId}/{colNO}/micopy")]
        public BaseResult CopyMiCabinet(long cabinetId, int colNO)
        {
            return _roomService.CopyMCabinets(cabinetId, colNO);
        }

        /// <summary>
        /// 查询柜子
        /// </summary>
        /// <returns></returns>
        [HttpGet("cabinet/{areaId}/query")]
        public BaseGenericResult<List<CabinetQueryDto>> QueryCabinets(long areaId)
        {
            var _user = TokenHelper.GetTokenInfo<TokenData>(User);
            return _roomService.QueryCabinets(areaId, _user.OrganId);
        }

        /// <summary>
        /// 删除柜子
        /// </summary>
        /// <returns></returns>
        [HttpDelete("cabinet/delete")]
        public BaseResult DeleteCabinet([FromBody] DeleteSingleDto query)
        {
            return _roomService.DeleteCabinet(query);
        }

        /// <summary>
        /// 删除密集柜列
        /// </summary>
        /// <returns></returns>
        [HttpGet("cabinet/{cabinetId}/{colNO}/midelete")]
        public BaseResult DeleteMiCabinet(long cabinetId, int colNO)
        {
            return _roomService.DeleteMiCabinet(cabinetId, colNO);
        }

        /// <summary>
        /// 添加箱子
        /// </summary>
        /// <returns></returns>
        [HttpPost("box/post")]
        public BaseResult PostBox([FromBody] List<List<BoxPostDto>> dto)
        {
            return _roomService.PostBox(dto);
        }
        /// <summary>
        /// 编辑箱子
        /// </summary>
        /// <returns></returns>
        [HttpPost("box/put")]
        public BaseResult PutBox([FromBody] BoxPutDto dto)
        {
            return _roomService.PutBox(dto);
        }
        /// <summary>
        /// 查询箱子
        /// </summary>
        /// <returns></returns>
        [HttpGet("box/{cabinetId}/{col}/{direction}/query")]
        public BaseGenericResult<BoxQueryAllDto> QueryBoxs(long cabinetId, int col, int direction)
        {
            var _user = TokenHelper.GetTokenInfo<TokenData>(User);
            return _roomService.QueryBoxs(cabinetId, col, direction, _user.OrganId);
        }
        /// <summary>
        /// 清空箱子
        /// </summary>
        /// <returns></returns>
        [HttpGet("box/{cabinetId}/{col}/{direction}/{row}/delete")]
        public BaseResult DeleteBoxs(long cabinetId, int col, int direction, int row)
        {
            return _roomService.DeleteBoxs(cabinetId, col, direction, row);
        }

        /// <summary>
        /// 硬件开柜子
        /// </summary>
        /// <returns></returns>
        [HttpPost("box/open")]
        public BaseGenericResult<List<OpenBoxDto>> OpenBox(OpenBoxDto dto)
        {
            return _roomService.OpenBox(dto);
        }

        /// <summary>
        /// 更改位置开柜子
        /// </summary>
        /// <returns></returns>
        [HttpPost("changebox/open")]
        public BaseGenericResult<List<OpenBoxDto>> ChangeLocOpenBox(OpenBoxDto dto)
        {
            return _roomService.ChangeLocOpenBox(dto);
        }
    }
}
